using ASP;
using HoWave.Web;
using HoWave.Web.DataHelper;
using HoWave.Web.Shop;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Witkey_AttendWitkey : Shop, IRequiresSessionState
{
	private string type = "";
	protected Label Label_Title;
	protected DropDownList DropDownList_Statu;
	protected TextBox TextBox_Title;
	protected DropDownList DropDownList_Price;
	protected Button search;
	protected GridView GridView1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.type = base.Request.QueryString["type"].ToString();
		if (!base.IsPostBack)
		{
			if (this.type == "attend_1")
			{
				this.Label_Title.Text = "我参加的悬赏任务";
			}
			if (this.type == "attend_2")
			{
				this.Label_Title.Text = "我发布的悬赏任务";
			}
			this.Initpage();
		}
	}
	protected void Initpage()
	{
		if (this.type == "attend_1")
		{
			this.AttendBind("", 0);
			this.Label_Title.Text = "我参加的悬赏任务";
		}
		if (this.type == "attend_2")
		{
			this.AttendBind(0, "");
			this.Label_Title.Text = "我发布的悬赏任务";
		}
		this.UpdateEnd();
	}
	protected void UpdateEnd()
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		DataTable witkeyAll = shop_Witkey.GetWitkeyAll();
		DateTime now = DateTime.Now;
		foreach (DataRow dataRow in witkeyAll.Rows)
		{
			DateTime t = Convert.ToDateTime(dataRow["ww_EndTime"]);
			if (now >= t)
			{
				string a = dataRow["ww_Statu"].ToString();
				if (a != "8" && a != "9" && a != "7" && a != "5" && a != "6" && a != "5" && a != "1")
				{
					shop_Witkey.UpdateWitkeyStatu(Convert.ToInt32(dataRow["ww_Id"]), 7);
					int userID = Convert.ToInt32(dataRow["ww_Uid"]);
					UserBll userBll = new UserBll(this.conn);
					DataTable userByUserID = userBll.GetUserByUserID(userID);
					userBll.UpdateUserScope(userID, Convert.ToDecimal(userByUserID.Rows[0]["Balance"]) + Convert.ToDecimal(dataRow["ww_xsPrice"]), Convert.ToInt32(userByUserID.Rows[0]["UserEP"]));
				}
			}
		}
	}
	protected void AttendBind(int statu, string title)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.GridView1.DataSource = shop_Witkey.GetWitkeyAllByType(base.user.UserID, 1, 0, "", "", statu, title);
		this.GridView1.DataBind();
	}
	protected void AttendBind(string title, int statu)
	{
		Shop_Witkey shop_Witkey = new Shop_Witkey(this.conn);
		this.GridView1.DataSource = shop_Witkey.GetWitkeyUser(base.user.UserID, 1, title, statu);
		this.GridView1.DataBind();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			HyperLink hyperLink = (HyperLink)e.Row.FindControl("HyperLink_Edit");
			HyperLink hyperLink2 = (HyperLink)e.Row.FindControl("HyperLink_Give");
			HyperLink hyperLink3 = (HyperLink)e.Row.FindControl("HyperLink_End");
			DataRowView dataRowView = e.Row.DataItem as DataRowView;
			string text = dataRowView["ww_xsPrice"].ToString();
			string text2 = dataRowView["ww_Statu"].ToString();
			int num = Convert.ToInt32(dataRowView["ww_Complete"]);
			if (base.Request.QueryString["type"].ToString() != "attend_1")
			{
				if (hyperLink != null)
				{
					hyperLink.Visible = true;
				}
				if (hyperLink2 != null)
				{
					hyperLink2.Visible = false;
				}
				if (hyperLink3 != null)
				{
					hyperLink3.Visible = false;
				}
				if (num > 0)
				{
					hyperLink.Visible = false;
				}
				string text3 = text2;
				if (text3 != null)
				{
					if (!(text3 == "任务结束"))
					{
						if (!(text3 == "冻结"))
						{
							if (!(text3 == "未付款"))
							{
								if (text3 == "任务失败")
								{
									hyperLink3.Visible = false;
									hyperLink.Visible = false;
								}
							}
							else
							{
								hyperLink2.Visible = true;
							}
						}
						else
						{
							hyperLink3.Visible = false;
							hyperLink.Visible = false;
						}
					}
					else
					{
						hyperLink3.Visible = true;
						hyperLink.Visible = false;
					}
				}
			}
			else
			{
				if (hyperLink != null)
				{
					hyperLink.Visible = false;
				}
				if (hyperLink2 != null)
				{
					hyperLink2.Visible = false;
				}
				if (hyperLink3 != null)
				{
					hyperLink3.Visible = false;
				}
			}
		}
	}
	protected void search_Click(object sender, EventArgs e)
	{
		int statu = int.Parse(this.DropDownList_Statu.SelectedValue);
		string text = this.TextBox_Title.Text;
		if (this.type == "attend_1")
		{
			this.AttendBind(text, statu);
			this.Label_Title.Text = "我参加的悬赏任务";
		}
		if (this.type == "attend_2")
		{
			this.AttendBind(statu, text);
			this.Label_Title.Text = "我发布的悬赏任务";
		}
	}
}
